package cn.shop.cloud.mapper;

import cn.shop.cloud.domain.SeckillGood;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @program: shop-parent
 * @ClassName SeckillGoodMapper
 * @description:
 * @author: Mokio
 * @create: 2024−12-24 20:54
 * @Version 2024 2.2 ; jdk1.8.0_181
 **/
// 秒杀商品功能持久层
@Mapper
public interface SeckillGoodMapper {
    @Select("SELECT * FROM t_seckill_goods")
    public List<SeckillGood> query();

    @Select("SELECT * FROM t_seckill_goods where id=#{seckillId}")
    public SeckillGood get(Long seckillId);

    @Update("update t_seckill_goods set stock_count=stock_count-1 where id=#{seckillId} and stock_count>0")
    public  void decrStock(Long seckillId);

    @Select("SELECT stock_count FROM t_seckill_goods WHERE id=#{seckillId}")
    public int getStockCount(Long seckillId);
    @Update("update t_seckill_goods set stock_count=stock_count+1 where id=#{seckillId} and stock_count>0")
    public void incrStock(Long seckillId);

    // redis 和 mysql数据同步
}
